package zeno.project.springboot.controller.core;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import zeno.project.springboot.jms.MsgProducer;

import javax.annotation.Resource;
import javax.jms.Destination;

/**
 * @author ZhiYong
 * @ClassName ActiveMqController.java
 * @Description 消息队列测试
 * @createTime 2021/04/17 17:02:00
 * 找到安装目录 D:\Applications\apache-activemq-5.16.1\bin\win64 启动mq文件：activemq.bat，
 * 访问 http://127.0.0.1:8161/admin/， admin/admin
 */
@RestController
@RequestMapping("/activemq")
@Api(value = "消息队列测试")
public class ActiveMqController {

    private static final Logger logger = LoggerFactory.getLogger(ActiveMqController.class);

    @Resource
    private MsgProducer producer;
    @Resource
    private Destination queue;
    @Resource
    private Destination topic;

    @GetMapping("/send/queue")
    @ApiOperation(value = "开始发送点对点消息")
    public String sendQueueMessage(@RequestParam(value = "msg") String msg) {
        logger.info("===开始发送点对点消息===");
        producer.sendMessage(queue, "Queue: " + msg + " !");
        return "send queue success";
    }

    @GetMapping("/send/topic")
    @ApiOperation(value = "开始发送订阅消息")
    public String sendTopicMessage(@RequestParam(value = "msg") String msg) {
        logger.info("===开始发送订阅消息===");
        producer.sendMessage(topic, "Topic: " + msg + " !");
        return "send topic success";
    }
}
